﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbAdapter.sqldbAdapter;
using System.Data;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    /// <summary>
    /// 劳保库存查询
    /// </summary>
    public class DataAccessArticleInfoSel
    {
        /// <summary>
        ///出入库库存数量
        /// </summary>
        /// <returns></returns>
        public int GetArticleInfoSelCount(string condition)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Work_Article_Stocks_View where 1=1 " + condition + "";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取出入库库存信息
        /// </summary>
        /// <returns></returns>
        public DataSet SelArticleInfoSelInfo(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY ArticleNO ASC) rownumber,* " +
                               "from Work_Article_Stocks_View where STOCKS_COUNT!=0) B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString() + strquery;
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }
         /// <summary>
        /// 获取指定日期的数量
        /// </summary>
        /// <returns></returns>
        public DataSet GetPlanCount(string obj)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                string query = "EXEC PROC_Purchase_Plan '" + obj + "',0";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 获取领取信息
        /// </summary>
        /// <returns></returns>
        public DataSet GetInfomation(int pid)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();

                string query = "select * from (select * from  [Work_Post_Relation]  " +
                                "where postid=(select 岗位编号 as postid from FILE_PERSONNEL_VIEW  where Pid='" + pid + "')) R " +
                                "inner join (select ruleid as unitid,articleId from Work_Person_Unit_Post where personno='" + pid + "' ) T " +
                                 "on R.articleId=T.articleId";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 获取所有人员
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllPerson()
        {

            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();

                string query = " select * from dbo.FILE_PERSONNEL_VIEW where 工作状态='在职' and 卡状态='正常'";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }
    }
}
